﻿using MediatR;
using W.Carrier.Api.Application.Command;
using W.Carrier.Repostiory.Interface;

namespace W.Carrier.Api.Application.CommandHandler
{
    public class CarrierDeleteRangeCommandHandler:IRequestHandler<CarrierDeleteRangeCommand,int>
    {
        private readonly ICarrierInfoRepository _icarrierInfoRepository;
        public CarrierDeleteRangeCommandHandler(ICarrierInfoRepository icarrierInfoRepository)
        {
            _icarrierInfoRepository = icarrierInfoRepository;
        }

        public async Task<int> Handle(CarrierDeleteRangeCommand request, CancellationToken cancellationToken)
        {
            var list = await _icarrierInfoRepository.GetAllAsync();
            var plist=list.Where(c=>request.Ids.Contains(c.CarrierId)).ToList();
            foreach (var item in plist)
            {
                item.IsDelete = true;
            }
            int n = await _icarrierInfoRepository.UpdateRange(plist);
            return n;
        }
    }
}
